package com.zh.mp.demo.listener;

import com.zh.mp.demo.asyn.FutureService;
import com.zh.mp.demo.event.UserEvent;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

@Component
public class UserListener implements ApplicationListener<UserEvent> {

    private final FutureService futureService;

    @Autowired
    public UserListener(FutureService futureService){
        this.futureService = futureService;
    }

    @SneakyThrows
    @Override
    public void onApplicationEvent(UserEvent userEvent) {
        System.out.println(">>>>>>>>>UserListener>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        Future<Boolean> result = this.futureService.testUser(userEvent.getId());
        System.out.println(result.isDone());
        System.out.println("收到了：" + userEvent.getSource() + "消息;时间：" + userEvent.getTimestamp());
        System.out.println("消息：" + userEvent.getId() + ":" + userEvent.getMessage());
    }
}
